package marmalius.quest;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import marmalius.Player;

public class QuestService {
	private static final QuestService instance = new QuestService();
	private Map<Integer, BaseQuest> quests;
	
	
	public QuestService() {
		quests = new HashMap<Integer, BaseQuest>();
		
		quests.put(0, new Tutorial());
	}
	
	public boolean talkToNPC(Player player, int npcID) {
		for(Entry<Integer, BaseQuest> entry : quests.entrySet()) {
			BaseQuest quest = entry.getValue();
			if (!quest.isAlreadyDone(player) && quest.talkToNPC(player, npcID))
				return true;
		}
		return false;
	}
	
	public boolean autoTalkToNPC(Player player) {
		for(Entry<Integer, BaseQuest> entry : quests.entrySet()) {
			BaseQuest quest = entry.getValue();
			if (!quest.isAlreadyDone(player) && quest.autoTalkToNPC(player))
				return true;
		}
		return false;
	}
	
	public void process(Player player) {
		for(Entry<Integer, BaseQuest> entry : quests.entrySet()) {
			BaseQuest quest = entry.getValue();
			if (!quest.isAlreadyDone(player))
				quest.process(player);
		}
	}
	
	public void playerLogIn(Player player) {
		for(Entry<Integer, BaseQuest> entry : quests.entrySet()) {
			BaseQuest quest = entry.getValue();
			if (!quest.isAlreadyDone(player))
				quest.playerLogIn(player);
		}
	}
	
	public void playerQuestEvent(Player player, QuestEvent questEvent) {
		for(Entry<Integer, BaseQuest> entry : quests.entrySet()) {
			BaseQuest quest = entry.getValue();
			if (!quest.isAlreadyDone(player))
				quest.questEvent(player, questEvent);
		}
	}
	
	public static QuestService getInstance() { return instance; }
}
